Skip to content

kmem: don't add __GFP_RECLAIMABLE for KM_VMEM allocations#18107

Merged
behlendorf merged 1 commit intoopenzfs:masterfrom
robn:linux-6.19-compat-more
Jan 5, 2026
Merged

kmem: don't add __GFP_RECLAIMABLE for KM_VMEM allocations#18107
behlendorf merged 1 commit intoopenzfs:masterfrom
robn:linux-6.19-compat-more

Conversation

@robn
Copy link
Member

@robn robn commented Jan 4, 2026

Description

Possibly another GFP flag misuse, now warned about in 6.19.

20:35:38.27 2025-12-31T20:20:12,760105+11:00 Unexpected gfp: 0x10 (__GFP_RECLAIMABLE). Fixing up to gfp: 0x2c00 (GFP_NOIO|__GFP_NOWARN). Fix your code!
20:35:38.27 2025-12-31T20:20:12,760109+11:00 WARNING: mm/vmalloc.c:3939 at __vmalloc_noprof+0x69/0x80, CPU#3: spl_kmem_cache/55109
...
20:35:38.27 2025-12-31T20:20:12,760182+11:00 Call Trace:
20:35:38.27 2025-12-31T20:20:12,760185+11:00  <TASK>
20:35:38.27 2025-12-31T20:20:12,760189+11:00  kv_alloc+0x2a/0x70 [spl]
20:35:38.27 2025-12-31T20:20:12,760203+11:00  spl_slab_alloc+0x20/0x120 [spl]
20:35:38.27 2025-12-31T20:20:12,760210+11:00  __spl_cache_grow+0x2c/0xb0 [spl]
20:35:38.27 2025-12-31T20:20:12,760215+11:00  spl_cache_grow_work+0x1c/0x60 [spl]
20:35:38.27 2025-12-31T20:20:12,760221+11:00  taskq_thread+0x27d/0x5d0 [spl]
20:35:38.27 2025-12-31T20:20:12,760230+11:00  ? __pfx_default_wake_function+0x10/0x10
20:35:38.27 2025-12-31T20:20:12,760233+11:00  ? __pfx_spl_cache_grow_work+0x10/0x10 [spl]
20:35:38.27 2025-12-31T20:20:12,760240+11:00  ? __pfx_taskq_thread+0x10/0x10 [spl]
20:35:38.27 2025-12-31T20:20:12,760247+11:00  kthread+0xfc/0x240
20:35:38.27 2025-12-31T20:20:12,760250+11:00  ? __pfx_kthread+0x10/0x10
20:35:38.27 2025-12-31T20:20:12,760253+11:00  ret_from_fork+0x254/0x290
20:35:38.27 2025-12-31T20:20:12,760256+11:00  ? __pfx_kthread+0x10/0x10
20:35:38.27 2025-12-31T20:20:12,760258+11:00  ret_from_fork_asm+0x1a/0x30
20:35:38.27 2025-12-31T20:20:12,760261+11:00  </TASK>

On the surface its simple: vmalloc'd memory is (apparently) not movable/reclaimable, so __GFP_RECLAIMABLE is not a valid for it. This commit fixes that.

However, I'm concerned that means the shrinker will not call the kmem cache reclaim functions when necessary. I'm not sure either way. include/linux/gfp_types.h says:

 * %__GFP_RECLAIMABLE is used for slab allocations that specify
 * SLAB_RECLAIM_ACCOUNT and whose pages can be freed via shrinkers.

So I wonder if we should be backing kmem caches with memory from reclaimable slabs?

(Or I could just be making up words; I don't know the SPL kmem cache code very well. Though, I have wondered if the kernel's kmem_caches are good-enough these days to just use them directly?)

How Has This Been Tested?

ZTS run against 6.19-rc3 tripped the warning initially. A followup run with this patch passed and didn't warn. That may not be enough to definitely say that it's benign but its a start.

Haven't tested on older kernels; I'll see what CI shakes out first.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Performance enhancement (non-breaking change which improves efficiency)
  • Code cleanup (non-breaking change which makes code smaller or more readable)
  • Quality assurance (non-breaking change which makes the code more robust against bugs)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Library ABI change (libzfs, libzfs_core, libnvpair, libuutil and libzfsbootenv)
  • Documentation (a change to man pages or other documentation)

Checklist:

vmalloc()'d memory is not movable/reclaimable, so __GFP_RECLAIMABLE is
not a valid flag, and since 6.19 the kernel warns if you use it.

Sponsored-by: https://despairlabs.com/sponsor/
Signed-off-by: Rob Norris <robn@despairlabs.com>
Copy link
Member

@amotin amotin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I understand, the purpose of __GFP_RECLAIMABLE is to group together allocations of reclaimable memory, so that under pressure shrinker had some higher chances to free contiguous chunks without depending on relocation. I don't think it in any way affects shrinker operation itself. I can speculate that for virtually-mapped memory (unlike physically mapped) fragmentation can be some less of a problem, but it is only a speculation. So if you believe this is right now -- I won't object.

Copy link
Contributor

@behlendorf behlendorf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it doesn't make sense to set this for vmalloc virtual memory allocations so the warning here is spot on. This looks good.

I have wondered if the kernel's kmem_caches are good-enough these days to just use them directly?

That's a good question. We should already be using them for most things since any kmem cache with small object sizes will be backed by linux slabs. Where we potentially run in to problems is when abd_scatter_enabled=0, in which cache the kmem caches are expected to handled up to 16M objects. The last I checked the kernel slabs simply don't handle this. That said, these days we might be able to impose a similar cap of the kmem caches and wire the ABD code up on the Linux side to its own custom allocator.

@behlendorf behlendorf added the Status: Accepted Ready to integrate (reviewed, tested) label Jan 5, 2026
@behlendorf behlendorf merged commit a1319bf into openzfs:master Jan 5, 2026
26 checks passed
@robn robn deleted the linux-6.19-compat-more branch January 9, 2026 02:37
amotin pushed a commit to amotin/zfs that referenced this pull request Jan 29, 2026
vmalloc()'d memory is not movable/reclaimable, so __GFP_RECLAIMABLE is
not a valid flag, and since 6.19 the kernel warns if you use it.

Sponsored-by: https://despairlabs.com/sponsor/
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Alexander Motin <alexander.motin@TrueNAS.com>
Signed-off-by: Rob Norris <robn@despairlabs.com>
Closes openzfs#18107
mcmilk pushed a commit to mcmilk/zfs that referenced this pull request Jan 31, 2026
vmalloc()'d memory is not movable/reclaimable, so __GFP_RECLAIMABLE is
not a valid flag, and since 6.19 the kernel warns if you use it.

Sponsored-by: https://despairlabs.com/sponsor/
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Alexander Motin <alexander.motin@TrueNAS.com>
Signed-off-by: Rob Norris <robn@despairlabs.com>
Closes openzfs#18107
amotin pushed a commit to amotin/zfs that referenced this pull request Feb 3, 2026
vmalloc()'d memory is not movable/reclaimable, so __GFP_RECLAIMABLE is
not a valid flag, and since 6.19 the kernel warns if you use it.

Sponsored-by: https://despairlabs.com/sponsor/
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Alexander Motin <alexander.motin@TrueNAS.com>
Signed-off-by: Rob Norris <robn@despairlabs.com>
Closes openzfs#18107
lundman pushed a commit to openzfsonosx/openzfs-fork that referenced this pull request Feb 5, 2026
vmalloc()'d memory is not movable/reclaimable, so __GFP_RECLAIMABLE is
not a valid flag, and since 6.19 the kernel warns if you use it.

Sponsored-by: https://despairlabs.com/sponsor/
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Alexander Motin <alexander.motin@TrueNAS.com>
Signed-off-by: Rob Norris <robn@despairlabs.com>
Closes openzfs#18107
tonyhutter pushed a commit that referenced this pull request Feb 5, 2026
vmalloc()'d memory is not movable/reclaimable, so __GFP_RECLAIMABLE is
not a valid flag, and since 6.19 the kernel warns if you use it.

Sponsored-by: https://despairlabs.com/sponsor/
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Alexander Motin <alexander.motin@TrueNAS.com>
Signed-off-by: Rob Norris <robn@despairlabs.com>
Closes #18107
lundman pushed a commit to openzfsonwindows/openzfs that referenced this pull request Feb 23, 2026
vmalloc()'d memory is not movable/reclaimable, so __GFP_RECLAIMABLE is
not a valid flag, and since 6.19 the kernel warns if you use it.

Sponsored-by: https://despairlabs.com/sponsor/
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Alexander Motin <alexander.motin@TrueNAS.com>
Signed-off-by: Rob Norris <robn@despairlabs.com>
Closes openzfs#18107
lundman pushed a commit to openzfsonwindows/openzfs that referenced this pull request Feb 23, 2026
vmalloc()'d memory is not movable/reclaimable, so __GFP_RECLAIMABLE is
not a valid flag, and since 6.19 the kernel warns if you use it.

Sponsored-by: https://despairlabs.com/sponsor/
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Alexander Motin <alexander.motin@TrueNAS.com>
Signed-off-by: Rob Norris <robn@despairlabs.com>
Closes openzfs#18107
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Status: Accepted Ready to integrate (reviewed, tested)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants